# 2013-12-30
MySQL_Install() {
cd $CWD
logs "Info" "Add system user \"mysql\""
user_add mysql
logs "Info" "Decompress ${MySQLFileName}.tar.gz ..."
tar -zxf ${MySQLFileName}.tar.gz
cd ${MySQLFileName}
# 判断openssl的版本，如果低于0.9需要打补丁，主要针对RHEL5/CentOS5平台
SSLV=`openssl version | awk '{print $2}' | cut -c 1-3`
if [ "$SSLV" = "0.9" ] ; then
    logs "Info" "Make patch for MySQL (OpenSSL<1.0) ..."
    tar zxf $CWD/mysql-openssl.patch.tgz
    patch -p1 < mysql-openssl.patch
fi
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/usr/local/mysql/etc/my.cnf \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=yes
make && make install
mkdir -p /usr/local/mysql/etc
mkdir -p /usr/local/mysql/var/run
mkdir /usr/local/mysql/var/log
#cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
[ -f /etc/my.cnf ] && mv /etc/my.cnf /etc/my.cnf.org
cp $CWD/conf/my.512.cnf /usr/local/mysql/etc/my.cnf
ln -s /usr/local/mysql/etc/my.cnf /etc/my.cnf
#cp $CWD/conf/mysql.init /etc/init.d/mysql
cp support-files/mysql.server /etc/init.d/mysql
sed -i 's#basedir/my.cnf#basedir/etc/my.cnf#g' /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /usr/local/bin/mysqladmin
ln -s /usr/local/mysql/bin/mysqldump /usr/local/bin/mysqldump
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/usr/local/mysql/etc/my.cnf \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql
chkconfig --add mysql >/dev/null 2>&1 && chkconfig --level 345 mysql on
if [ "$?" != "0" ] ; then
   if [ "$linux_type" = "rhel" ] ; then
      echo "/etc/init.d/mysql start" >> /etc/rc.local
   else
      sed -i '/exit 0/i\/etc/init.d/mysql start' /etc/rc.local
   fi
fi
/etc/init.d/mysql start
#/usr/local/mysql/bin/mysqladmin -u root password $mysqlrootpwd
/usr/local/mysql/bin/mysql -e "grant all on *.* to test@'localhost' identified by 'test'"
#/usr/local/mysql/bin/mysql -e "grant all on *.* to test@'%' identified by 'test'"
}